﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace PMS.DAL
{
    public class ShelfDAL
    {
        public bool IsExist(string name)
        {
            string strsql = "select Id from P_Shelf where ShelfName='"+name+"'";
            return Convert.ToBoolean(DBUtility.SQLHelper.Execute(strsql));
        }
        public bool Insert(Model.Shelf shelf)
        {
            string strsql = "Insert into P_Shelf (DepotId,ShelfName) values(?,?)";
            OleDbParameter[] parameters = new OleDbParameter[2];
            parameters[0] = new OleDbParameter("?",shelf.DepotId);
            parameters[1] = new OleDbParameter("?", shelf.ShelfName);
            return Convert.ToBoolean(DBUtility.SQLHelper.Execute(strsql,parameters));
        }

        public IList<Model.Shelf> GetList(string strWhere)
        {
            string sql = "select Id,DepotId,ShelfName from P_Shelf";
            List<Model.Shelf> ShelfList = new List<PMS.Model.Shelf>();
            System.Data.DataSet ds = DBUtility.SQLHelper.GetData(sql);
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                Model.Shelf shelf = new PMS.Model.Shelf();
                shelf.Id = (int)row[0];
                shelf.DepotId = (string)row[1];
                shelf.ShelfName = (string)row[2];
                ShelfList.Add(shelf);
                shelf = null;
            }
            return ShelfList;
        }        
    }
}
